package test.core.fun;

import java.io.Serializable;

import test.core.data.MyFst;
import test.core.data.MySerial;

public class testFstKryo {
	public static void main(String[] args) {
		User2 bean = new User2();
		bean.setUsername("xxxxx");
		bean.setPassword("123456");
		bean.setAge(1000000);
		System.out.println("序列化 ， 反序列化 对比测试：");
		int max = 200000;

		// 因为
		MyFst mf = MyFst.getInstance();

		long size = 0;
		long time1 = System.currentTimeMillis();
		for (int i = 0; i < max; i++) {
			byte[] jdkserialize = MySerial.serialize(bean);
			size += jdkserialize.length;
			MySerial.deserialize(jdkserialize);
		}
		System.out.println("原生序列化方案[序列化" + max + "次]耗时：" + (System.currentTimeMillis() - time1) + "ms size:=" + size);

		size = 0;
		long time2 = System.currentTimeMillis();
		for (int i = 0; i < max; i++) {
			byte[] serialize = mf.serialize(bean);
			size += serialize.length;
			User2 u = (User2) mf.deserialize(serialize);
		}
		System.out.println("fst序列化方案[序列化" + max + "次]耗时：" + (System.currentTimeMillis() - time2) + "ms size:=" + size);
		size = 0;
		
		hyl.core.reflect.MyKryo mk=hyl.core.reflect.MyKryo.getInstance();
		long time3 = System.currentTimeMillis();
		for (int i = 0; i < max; i++) {
			byte[] serialize =mk.serialize(bean);
			size += serialize.length;
			User2 u = (User2) mk.deserialize(serialize);
		}
		System.out.println("kryo序列化方案[序列化" + max + "次]耗时：" + (System.currentTimeMillis() - time3) + "ms size:=" + size);

	}

}

class User2 implements Serializable {

	private String username;
	private int age;
	private String password;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}